<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-10-14
 * Time: 16:16:10
 * Info:
 */

namespace plugin\huiblog\app\model;

use think\Model;
use think\facade\Db;

class Action extends Model
{

    protected $table = 'blog_action';

    /**
     * 自动时间戳类型
     * @var string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 添加时间
     * @var string
     */
    protected $createTime = 'create_time';

    /**
     * 更新时间
     * @var string
     */
    protected $updateTime = 'update_time';

    /**
     * @param $limit 每页数量
     * @param $page  是否开启分页
     */
    function lists($limit = 8, $page = false)
    {
        $map  = [];
        $sort = 'id desc';
        $list = Db::table('blog_action')->order($sort)->limit($limit)->paginate($limit)->each(function (
            $item
        ) {
            if ( ! empty($item['thumbs'])) {
                $item['thumbs'] = json_decode($item['thumbs'], true);
            }

            return $item;
        });

        return $list;
    }

}
